/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Santiago Ontanon, Kinshuk Mishra
 												Neha Sugandh 
 												
Class							:				SupplyCondition
 
Function						: 				Provides a class for holding a supply 
												condition 
****************************************************************************/
package planninglanguage.conditions;

import org.jdom.Element;

import util.XMLWriter;
import base.WargusGameState;
import base.WargusPlayer;

public class SupplyCondition extends Condition {
	int m_minSupply;
	public SupplyCondition(int a_minSupply)
	{
		m_minSupply = a_minSupply;
	}
	public String toString(int tabs)
	{
		String n = super.toString(tabs);
		n = n + "Min Supply is:" + m_minSupply;
		return n;
	}
	public boolean test(WargusGameState a_gameState)
	{		
//		System.out.println("SupplyCondition: test( supply = " + m_minSupply + ")");	
	
		WargusPlayer p = a_gameState.getPlayer();
		
		if (p!=null) {
			if (p.getFood() >= p.getDemand()+m_minSupply) return true;
		    else return false;
		}
		return false;		
	}
	
	public void writeXML(XMLWriter w) {
		w.tag("condition type=\""+this.getClass().getSimpleName()+"\"");
		{
			w.tag("min-supply", m_minSupply);
		}
		w.tag("/condition");
	}
	
	protected static Condition loadConditionFromXML(Element e) {
		return new SupplyCondition(Integer.parseInt(e.getChildText("min-supply")));
	}

}
